﻿using IMark.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.Admin.NewsType
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Utils.CheckAuthentication())
            {
                if (!IsPostBack)
                {
                    LoadData();
                }
            }
        }

        private void LoadData()
        {
            info.InnerHtml = string.Empty;
            if ((string)Session["Info"] != "")
            {
                info.InnerHtml = (string)Session["Info"];
                Session["Info"] = "";
            }

            List<LOAI_BAI_VIET> dataNewsType = LoaiBaiVietModels.GetAll();
            if (dataNewsType.Count > 0)
            {
                StringBuilder str = new StringBuilder();
                foreach (var item in dataNewsType)
                {
                    string urlUpdate = ResolveClientUrl("~/Admin/NewsType/Update.aspx?ID=" + item.ID);
                    string urlDelete = ResolveClientUrl("~/Admin/NewsType/Delete.aspx?ID=" + item.ID);

                    str.Append("<tr class=\"odd gradePhone\">");
                    str.Append("<td>" + item.Ten + "</td>");
                    str.Append("<td>" + item.MoTa + "</td>");
                    str.Append("<td>" + item.ThuTu + "</td>");

                    str.Append("<td class=\"text-center\">");
                    str.Append("<a href=\""+urlUpdate+"\" class=\"btn btn-primary btn-circle\" title=\"Cập nhật\">");
                    str.Append("<i class=\"fa fa-edit\"></i>");
                    str.Append("</a>");
                    str.Append("<button data-toggle=\"modal\" data-target=\"#modalDeleteItems\" onclick=\"return DeleteItems('" + urlDelete + "')\" class=\"btn btn-danger btn-circle\" type=\"button\" title=\"Xóa\">");
                    str.Append("<i class=\"fa fa-times\"></i>");
                    str.Append("</button>");
                    str.Append("</td>");
                    str.Append("</tr>");
                }
                lstNewsType.InnerHtml = str.ToString();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Admin/NewsType/Add.aspx");
        }
    }
}